// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   register_ok.java

package hr.salary_standard;

import include.nseer_cookie.GetWorkflow;
import include.nseer_cookie.counter;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataNumber;

public class register_ok extends HttpServlet
{

	ServletContext application;
	HttpSession session;

	public register_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		counter count = new counter(dbApplication);
		try
		{
			nseer_db_backup1 hr_db = new nseer_db_backup1(dbApplication);
			HttpSession session = request.getSession();
			PrintWriter out = response.getWriter();
			if (hr_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				ValidataNumber validata = new ValidataNumber();
				String standard_ID = request.getParameter("standard_ID");
				String standard_name = request.getParameter("standard_name");
				String register = request.getParameter("register");
				String register_time = request.getParameter("register_time");
				String major_type = request.getParameter("major_type");
				String designer = request.getParameter("designer");
				String item_name[] = request.getParameterValues("item_name");
				String salary[] = request.getParameterValues("salary");
				String details_number[] = request.getParameterValues("details_number");
				int p = 0;
				for (int i = 0; i < item_name.length; i++)
					if (!salary[i].equals(""))
					{
						StringTokenizer tokenTO4 = new StringTokenizer(salary[i], ",");
						String salary1;
						for (salary1 = ""; tokenTO4.hasMoreTokens(); salary1 = (new StringBuilder(String.valueOf(salary1))).append(tokenTO4.nextToken()).toString());
						if (!validata.validata(salary1))
							p++;
					}

				if (p == 0)
				{
					int n = 0;
					double salary_sum = 0.0D;
					for (int i = 0; i < item_name.length; i++)
						if (!salary[i].equals(""))
						{
							StringTokenizer tokenTO4 = new StringTokenizer(salary[i], ",");
							String salary1 = "";
							while (tokenTO4.hasMoreTokens()) 
							{
								salary1 = (new StringBuilder(String.valueOf(salary1))).append(tokenTO4.nextToken()).toString();
								if (salary1.indexOf("-") != -1)
									n++;
							}
						}

					if (n == 0)
					{
						try
						{
							String sql1 = (new StringBuilder("delete from hr_salary_standard where standard_ID='")).append(standard_ID).append("'").toString();
							hr_db.executeUpdate(sql1);
							String sql3 = (new StringBuilder("delete from hr_salary_standard_details where standard_ID='")).append(standard_ID).append("'").toString();
							hr_db.executeUpdate(sql3);
							for (int i = 0; i < item_name.length; i++)
							{
								if (salary[i].equals(""))
									salary[i] = "0";
								String salarying = "";
								for (StringTokenizer tokenTO = new StringTokenizer(salary[i], ","); tokenTO.hasMoreTokens();)
									salarying = (new StringBuilder(String.valueOf(salarying))).append(tokenTO.nextToken()).toString();

								salary_sum += Double.parseDouble(salarying);
								String sql4 = (new StringBuilder("insert into hr_salary_standard_details(standard_ID,standard_name,details_number,item_name,salary) values('")).append(standard_ID).append("','").append(standard_name).append("','").append(details_number[i]).append("','").append(item_name[i]).append("','").append(salarying).append("')").toString();
								hr_db.executeUpdate(sql4);
							}

							String mod = request.getRequestURI();
							count.writeTime((String)dbSession.getAttribute("unit_db_name"), mod);
							String sql2 = (new StringBuilder("insert into hr_salary_standard(standard_ID,standard_name,major_type,designer,register,register_time,salary_sum) values('")).append(standard_ID).append("','").append(standard_name).append("','").append(major_type).append("','").append(designer).append("','").append(register).append("','").append(register_time).append("','").append(salary_sum).append("')").toString();
							hr_db.executeUpdate(sql2);
							List rsList = GetWorkflow.getList(hr_db, "hr_config_workflow", "02");
							if (rsList.size() == 0)
							{
								String sql = (new StringBuilder("update hr_salary_standard set check_tag='1' where standard_ID='")).append(standard_ID).append("'").toString();
								hr_db.executeUpdate(sql);
							} else
							{
								String sql;
								for (Iterator ite = rsList.iterator(); ite.hasNext(); hr_db.executeUpdate(sql))
								{
									String elem[] = (String[])ite.next();
									sql = (new StringBuilder("insert into hr_workflow(config_id,object_ID,type_id,describe1,describe2) values ('")).append(elem[0]).append("','").append(standard_ID).append("','02','").append(elem[1]).append("','").append(elem[2]).append("')").toString();
								}

							}
						}
						catch (Exception ex)
						{
							out.println((new StringBuilder("error")).append(ex).toString());
						}
						response.sendRedirect("hr/salary_standard/register_ok_a.jsp");
					} else
					{
						response.sendRedirect("hr/salary_standard/register_ok_b.jsp");
					}
				} else
				{
					response.sendRedirect("hr/salary_standard/register_ok_c.jsp");
				}
				hr_db.commit();
				hr_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception exception) { }
	}
}
